{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<img align=\"left\" style=\"padding-right:10px;\" src=\"figures/PHydro-cover-small.png\">\n",
    "*This is the Jupyter notebook version of the [Python in Hydrology](http://www.greenteapress.com/pythonhydro/pythonhydro.html) by Sat Kumar Tomer.*\n",
    "*Source code is available at [code.google.com](https://code.google.com/archive/p/python-in-hydrology/source).*\n",
    "\n",
    "*The book is available under the [GNU Free Documentation License](http://www.gnu.org/copyleft/fdl.html). If you have comments, corrections or suggestions, please send email to satkumartomer@gmail.com.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [5. Statistics](05.00-Statistics.ipynb) | [Contents](Index.ipynb) | [Theoretical Distributions](05.02-Theoretical-Distributions.ipynb) >"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.1 经验分布\n",
    "\n",
    "大多数水文变量都是连续的，但由于我们的测量能力，我们对它们进行了离散测量。使用bin进行离散数据的分类，为离散数据的平均连续处理提供了手段。数据的底层分布的可视化是通过绘制直方图实现的。直方图描述离散区间上的频率。让我们从直方图开始。在下面的例子中，首先我们将生成一些虚拟的数据，然后计算并绘制直方图。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\laihetao\\AppData\\Local\\conda\\conda\\envs\\DataProcess\\lib\\site-packages\\ipykernel_launcher.py:9: DeprecationWarning: `histogram` is deprecated!\n",
      "scipy.stats.histogram is deprecated in scipy 0.17.0; use np.histogram instead\n",
      "  if __name__ == '__main__':\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import scipy.stats as st\n",
    "\n",
    "x = np.random.randn(100) #生成模拟数据\n",
    "\n",
    "# 计算直方图\n",
    "n,low_range,binsize,extrapoints = st.histogram(x)\n",
    "upper_range = low_range + binsize*(len(n)-1)\n",
    "bins = np.linspace(low_range,upper_range,len(n))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`st,histogram`提供了在每个区间(n)中bin的数量，bin的下限(low_range),bins的宽(binsize)，以及不用于计算直方图的点。由于bin的大小与所有的bin相同，所以Pyhon只提供一个bin的大小。我们使用bin 的下限和大小来计算bin的上限范围，然而计算所有bin的中农位数的值。现在可以使用`bar`绘制直方图。我们也将定义bar的宽度和颜色"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZEAAAETCAYAAAD3WTuEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAHc1JREFUeJzt3Xu4XFWZ5/Hvj4CEADaXnGAICUEEGhq5HiIMdA8MHQwMY0YuCiMSuRhBGEGh5aag0CCXDrYziOlwRyGiDUgeiUBENDiKcEKHkJAoF7kckibRcIuAGPPOH3sfU1aqTtapqn2qKvX7PM95au+1VtV+iyTnZa+111qKCMzMzGqxXrMDMDOz9uUkYmZmNXMSMTOzmjmJmJlZzZxEzMysZk4iZmZWMycRMzOrmZOImZnVzEnEzMxqtn6zAyja8OHDY+zYsc0Ow8ysbcyZM+d3EdGV0nadTyJjx46lp6en2WGYmbUNSS+ktnV3lpmZ1cxJxMzMapbcnSXpKOAIYBtgaHl9RIxrYFxmZtYGkpKIpK8AFwJPAE8B7xYYk5mZtYnUO5GTgMsj4vwigzEzs/aSOiayKfBgkYGYmVn7SU0i3wUmFBmImZm1n9TurAeBKyQNB2YBr5U3iIiZjQzMzMxaX2oSuSN/HQtMqlAfwJBGBGRmZu0jNYlsV2gUZq1I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JmZlYzJxEzM6uZk4iZmdXMScTMzGr2/wFhlchhAIPuEgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x218d3e55828>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.bar(bins,n,width=0.3,color='red')\n",
    "plt.xlabel('X',fontsize=20)\n",
    "plt.ylabel('number of data points in bin',fontsize=15)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center>图5.1:x的直方图</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据的直方图如图5.1所示。在这个例子中，因为我们刚刚从正态分布创建了100个随机数，直方图没有展示正态分布应该显示的行为。\n",
    "\n",
    "直方图中的每个bar都告诉我们，数据在特定的bin中有多少次。查看数据的行为的一个更好的方法是查看相对直方图，它告诉我们点在某一范围内发概率。通过将每个bin的频率除以所有箱中的频率之和，得到相对直方图或相对频率。相对直方图表示数据发生在bin中的数据的概率。要么是我们可以使用`histogram`函数先计算直方图，然后除以频率总数，要么是我们直接使用`relfreq`函数。`relfreq`提供了相对频率，连同其他与`histogram`类似的输出。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZcAAAETCAYAAAD6R0vDAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3X20HWV99vHvZRB8q4omWAhEosaXiBRlE2C14gsFg1ViFUoolVCpESoufaw+ghQpsVpfVkutRW2UVxXBYpGsCo0oILZFzAlGIGDwEEEOQUGDig8CBq7nj5kjO5u9z5l9zuyzs8+5PmvtdfbM3DPzm5Xk/DJzz/27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/iVMY2WVWubZqoUqYptkGSngJ8BXhXyxOQKZfk0ie2/7hi0/OBrzEgyWW865K0DHgdcKAH7D34Lv7MBl2VMk2xjZH0eIrE8kXb/9HveNLnsg2StKBp8VDgB/2KpU6SFgPvAw61fX+/44mOUlJpwJTTkpwJ3Gz7n/odD2QQ5TZJ0leAFwCPALcDx9m+s79RTV5Z0mcH4Oflqu/YPq6PIdVG0p8CnwTmAL8A1tl+zdh7bbskvRb4Zx4tqfShPodUC0lfAl5JUTn4p8Cpts/sa1A1kPRHwLeBGyh+bwC83/alfYspySUiIuqWx2IREVG7JJeIiKhdkktERNQuySUiImqX5BIREbVLcomIiNoluUT0kaS/kmRJl43R5mtlm7+eytgiJiPJJaKPbH+OYvT7Yklvb90u6XjgtcBltj811fFFTFQGUUb0maSdKOaDeTLwstHS/ZKeD3wP+A3FPDg/6V+UEd3JnUtEn9m+G3gr8CTgC5K2k7Qd8IVy3fIklhg0qYocsQ2wfYmksyjmuRmdeXQf4JxtocJtRLfyWCxiGyHp94DvA/PKVXcAe5YzC0YMlDwWi9hGlElkBUUl4lnA8UksMaiSXCK2EZKeSDHfzajD+xVLxGQluURsOz4GvBD4BLAOeIuk1/c3pIiJSZ9LxDZA0sHAf1G8krwPsAAYoph4bA/bP+tjeBFdy51LRJ9JegZwNvBb4C9sP2j7RuAU4FnAZ/oZX8REJLlE9N+ngV2Av7V9fdP6f6SYuvZNkv6iL5FFTFAei0X0kaQ3A+cBVwOvsv1Iy/b5wPXAFuAltkemPsqI7iW5RPSJpHkUiUMU41lu79Dur4DPApcDr3H+0cYASHKJiIjapc8lIiJql+QSERG1S3KJiIjaJblERETtklwiIqJ2SS4REVG7JJeIiKhdkktERNQuySXMwm8ZAAAAD0lEQVQiImqX5BIREbX7/zr4HLUfEFnsAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x218d3e55048>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "relfreqs,lowlim,binsize,extrapoints = st.relfreq(x)\n",
    "plt.bar(bins,relfreqs,width=0.3,color='magenta')\n",
    "plt.xlabel('X',fontsize=20)\n",
    "plt.ylabel('Relative frequencies',fontsize=15)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center>图5.2:$x$的相对直方图</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "因为我们使用的是前面例子中使用的`x`，所以我们不重新计算`bins`。在这个柱状图中，我们使用`magenta`(洋红色)颜色。不同的颜色的图形，只是为了让你对颜色和字体大小更熟悉。它并不意味着我们应该使用与直方图不同的颜色作为相对频率图；没有什么阻止我们使用相同的颜色。\n",
    "\n",
    "在相对直方图如图5.2所示。相对直方图告诉我们实验数据的如何表现的；在某些范围内数据有多少次(或者有多大概率)。相对直方图只告诉实验数据，关于我们拥有的数据。我们将来会得到什么数据呢？PDF是一个更好的指示器来说明将来的数据。随机变量的概率密度函数(pdf)是描述这个随机变量在给定点上发生的相对可能性的函数。随机变量落在某一特定区域的概率是由该区域上的变量密度的积分给出的的。概率密度函数在处处都是非负的，它在整个空间上的积分都等于1。我们可以用bin的大小除以相关频率得到pdf。一个简单的计算pdf的方法是使用`hist`函数。`hist`生成图形，并且还返回每个bin的pdf值。bin的数量由第二个参数来控制，在下面的例子中它被设为10。`bin`提供了bin的上下限，因此，它的长度比bin的数量多一个。除了颜色外，我们为`hist`函数指定了apha值。`alpha`值控制图的透明度；0.0意味着完全透明，1.0是表示完全不透明。PDF柱状图如图5.3所示。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAEPCAYAAABsj5JaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDI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OV04Z8Bnxh1EZqT2R7x87oR1aJ50jyF/CLgS6Ot5NjO6ABJ8lngxbMcuraq/mdVXQtcm+QaYCNwXacFzpPjnWfT51p6U+jf77K2+TTMeZ6GhnrEj04dSZ4L3Ab864FfQk46Z3SAVNUlQ3a9BfhfnKIBcrzzTHIl8AvAm+sUvq97Dn+fp5OhHvGjU0OSv0EvPH6/qv77qOs5Hq+BHEWSlX27a4GvjqqWhZRkDfB+YG1V/WDU9WjOhnk8kE4BzWsrPg48UFUfGXU9w3Ah4VEkuQ3428CTwF8AV1XVt0Zb1fxrHhlzLvBw03RXVV01wpIWRJJ/CPwmMAb8JXBvVZ0Wb7VM8vPAf+LI44G6elpDZ5L8N+BN9J5S+x3guqr6+EiLmmdJfhb4Y+B+ev/uAPxq8/SOk5IBIklqxZ+wJEmtGCCSpFYMEElSKwaIJKkVA0SS1IoBInUkyR1J/jTJ2QPtv5ikklw6qtqkNryNV+pIkp8E7gM2PbVQrHlsxQPAF6vqHaOsT5orZyBSR6rqq8B/BG5I8tRTVm8Ang/8m5EVJrXkDETqUJIfBfYCXwb+A3A38O+r6qMjLUxqwQCROpZkHfAp4BvAo8Br+97JIp0yDBBpBJJMAq8Ffq6q7hx1PVIbXgOROta8k/0ieu/teNNoq5HacwYidSjJWfTeMneY3vvoNwEXVNX+kRYmtWCASB1K8i+B3wD+LrAP2AN8tap+YaSFSS34E5bUkSQvAm4EfrOq7quqw8C7gbc1F9alU4ozEKkjSX4XuAT4yf53XSf5FPB3gFVV9dio6pPmyhmI1IEkFwP/BHhff3g03gO8CPjVzguTToAzEElSK85AJEmtGCCSpFYMEElSKwaIJKkVA0SS1IoBIklqxQCRJLVigEiSWjFAJEmt/H//Omaqyc7aowAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x218d68e2e10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "n, bins, patches = plt.hist(x, 10, normed=1, facecolor='yellow', alpha=0.5)\n",
    "plt.xlabel('X', fontsize=15)\n",
    "plt.ylabel('PDF', fontsize=15)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "累计分布函数(CDF)描述了一个给定概率分布的实值随机变量$X$在小于或等于x的值上的概率。`cumfreq`提供了数据的乐际概率，可以用来计算CDF。如果我们用累计频率除以总频率，就得到CDF。累计频率的最后一个值等于总频率，因此我们用这个来计算CDF。CDF如图5.4所示。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAEPCAYAAABcA4N7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAEGlJREFUeJzt3XuwXWV5x/HvTxCcesGpOU5bkhg6jZfUsUVP0Rk7FRVLoA6Z1kuhrVqlZpyKl3q0RemgYv1DmVNalVYzFR0dFfGG0aYFqzg6WijBCzUJ6aRU5YiViLdOUTD16R97B3ZOdt5zcjh77ZOd72cmM/td+2GtZw0Mv7xr7fWuVBWSJB3KfcbdgCRpZTMoJElNBoUkqcmgkCQ1GRSSpCaDQpLUZFBIkpoMCklSk0EhSWo6dtwNLIdVq1bVunXrxt2GJB1Rbrjhhu9W1dRCdRMRFOvWrWP79u3jbkOSjihJvrGYOi89SZKaDApJUpNBIUlqMigkSU0GhSSpqdOgSHJZktuSfO0Q3yfJW5LsSXJjksd22Z8k6WBdzyjeDWxsfH8GsL7/ZzPw9x30JElq6DQoqupzwPcaJZuA91TPtcCDk/xiN91JkoZZafcoTgRuGRjP9bdJksZkpT2ZnSHbamhhspne5SnWrl07yp4kaclmZ2dHuv+ZmZmR7h9W3oxiDlgzMF4N3DqssKq2VNV0VU1PTS24VIkkaYlWWlBsBZ7b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QDFFVpy2y9P3AP3IEB8VC55rkecDTgace6U/IH8a/10m0mOVzdARKcl96IfG+qvroKI7hPYrDlGT9wPAs4KZx9TJqSTYCfwGcVVV3jLsf3SuLWT5HR5gkobeaxa6q+uuRHecI/0ti55J8hN5qtT8DvgG8qKq+Nd6uRqO/jMrxwP6Ve6+tqheNsaWRSfK7wFuBKeAHwFeq6vTxdrW8kpwJ/A33LJ/zxjG3NBJJPgCcSm9F1e8Ar62qd461qRFJ8pvA54F/p/f/JIDX9FfAWL7jGBSSpBYvPUmSmgwKSVKTQSFJajIoJElNBoUkqcmgkJZZks8k+Wr/ne+D25+RpJI8bVy9SUvhz2OlZZbkkcCNwPn7H4LqL7GwC/hiVf3+OPuTDpczCmmZVdVNwCzw+iT7V/J8PXAC8Gdja0xaImcU0ggk+TlgJ/BvwF8BNwB/XlWXjLUxaQkMCmlEkmwCrgS+DvwIeNzA+z2kI4ZBIY1Qku3A44CnVNU14+5HWgrvUUgj0n/39sn03vtw6ni7kZbOGYU0AknuQ+9NY3fSe/f4+cCvVtXNY21MWgKDQhqBJH8KvAV4LLAb2AHcVFVPH2tj0hJ46UlaZkkeCrwReGtV3VhVdwIvBX6nf4NbOqI4o5CWWZL3AKcBjxx8f3GSK4FfAzZU1Y/H1Z90uJxRSMsoyW8BzwFmhrzk/mXAQ4HXdN6YdC84o5AkNTmjkCQ1GRSSpCaDQpLUZFBIkpoMCklSk0EhSWoyKCRJTQaFJKnJoJAkNf0/S9wb41mge6cAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x218d6b4fd30>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cumfreqs, lowlim, binsize, extrapoints = st.cumfreq(x)\n",
    "plt.bar(bins[:-1], cumfreqs/cumfreqs[-1], width=0.4, color='black', alpha=0.45)\n",
    "plt.xlabel('X', fontsize=15)\n",
    "plt.ylabel('CDF', fontsize=15)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们可以使用`scikits`库中的`CDF`函数直接估算经验累计分布函数(ECDF)。关于`scikits`的信息在这里http://pypi.python.org/pypi/scikits.statsmodels。\n",
    "经验分布函数(CDF)是与样本的经验测量相关联的累积分布函数。这个cdf是一个阶梯函数，在n个数据点的每一个上跳起1/n。经验分布函数估计样本中各点的基本cdf。在前面的例子中，我们在将数据分类到一些bin后估计了CDF(ECDF)。这意味着，我们假设数据在一些小范围内以相似统计的方式表现。我们也可以估计CDF而不用做这个假设，这将使用`ECDF`函数来完成。`ECDF`函数的输出是存储数据值以及对应的ECDF的对象。使用`ecdf.x`检索数据，使用`ecdf.y`检索相应的ECDF。`ecdf`是你定义的用于存储`ECDF`函数输出的变量名。如果你使用其他名称，你需要使用相同的名字来检索`x`和`y`属性。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from statsmodels.distributions.empirical_distribution import ECDF\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# 生成一些数据\n",
    "data = np.random.randn(100)\n",
    "\n",
    "#估计ecdf\n",
    "ecdf = ECDF(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们应该将ECDF作为一个阶梯图，因为每个ECDF都在一个小的区间上。ECDF图如图5.5所示。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAETCAYAAAAoF0GbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAGQtJREFUeJzt3XuwpHV95/H3x0ElWYUsMkauDkaSOGEtNRPQJbviLSIVYc16AWOiQIJJBaP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MOB04EHgg8s6o+2hv7GOC/AK8Dvk5zKtyCT1bVJ3vjfghsBf5PL4aHACf0fvefVNVrJ/LGpRYmCqknyX8EPkPzh/7RVfXt3vV9gU/QHIP59b5EsT9w/6r61sBzDgX+Gbi9d3xm/70CPlVVxy0Sw89U1VcGrj2A5rCq/wysq6pb7uNblZbFj56kXU7tff/ThSQBUFV3MuSc8qq6fTBJ9K5vp6lGfj7J4csJYDBJ9K7dRXPu9j7AU5bzPGkcPLhI2uVxve+fGnLv0zSnC+4mybHAS2m2R38o8ICBIYcAN40aQC+xvJomIRwO/MSQ50mdMlFIuyxMWH9j8EZV/SjJbf3XkjyLpnK4E/gYzUdW3wfuBY4DnkgzVzGSJI+g+cjq39MkpsuB24EfAeuAFy7nedK4mCikXW7vff9p4Mb+G0nW0Ews988PvBG4C9hQVdcPjD+PJlEsx8t7v+PUqrpg4Hmn0CQKqXPOUUi7fL73fdgf8P+JPf9i9Uhg65AkcT/glxf5HfcCaxa598je90uG3Ftu0pHGxkQh7XJB7/tZSQ5YuNhb9fRnQ8Z/jeY87IP7xoZmCez6RX7HbcBhi9z7Wu/7cf0Xkzwd+K3WyKUJ8qMnqaeqPpPkr4CXAF9KMthHsWPgH3kb8C7gC0ku6Y09liZJfBh45pBfcwVwcpIPA9fQTJBfWVVXAu+kWXn1/t7zbgGOAo4HLgaeN8a3K43MikLa3UtpEsXtwIuBU4DNwFNp5iN+rKrOo/mDfQfN/MGvAzcDx7DrY6xhz38vcDTwWpp5jif3nnct8CTgn2ia7H4X2A/4NZqEJE2FDXeSpFZWFJKkViYKSVIrE4UkqZWJQpLUykQhSWplopAktTJRSJJamSgkSa1MFJKkViYKSVKr/w+TkGKsmO2McAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x218d68b6978>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.step(ecdf.x,ecdf.y)\n",
    "plt.xlabel('data',fontsize=20)\n",
    "plt.ylabel('Empirical CDF',fontsize=15)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center>图5.5：使用普通方法的经验观测CDF估计值</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们也可以使用`ecdf`估计在任何数据值的ECDF。让我们在一些数据点(在零)评估和打印的ECDF的值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5\n"
     ]
    }
   ],
   "source": [
    "print(ecdf(0))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "用上述方法估计的经验CDF在阶梯函数中，看起来不太好。一种更好的估计ECDF的方法是使用kernel函数。这可以通过`statistics`模块完成。`statistics`模块提供了使用各种kernel函数用于估计PDF和CDF。`cpdf`函数用于估计CDF。我们还定义了kernal的名称(Epanechnikov)。可利用的kernal在`statiscics`库网站给出。在`legend`(图例)内部，在`legend`中，我们将图例的位置(loc)定义为`best`，这意味着Python会尝试将图例置于其中，以尽量减少对图的干扰。使用该曲线后的结果图如图5.6所示。从图中可以看出，与一般的ECDF估计方法相比，这显示了更平滑的变化。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'statistics' has no attribute 'cpdf'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-9-8e5f387c44cb>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mstatistics\u001b[0m \u001b[1;31m#经测试仅适合于低版本python\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstatistics\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcpdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mkernel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'Epanechnikov'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mecdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mecdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'Ordinary'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'Kernel'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mxlabel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'data'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mfontsize\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m20\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: module 'statistics' has no attribute 'cpdf'"
     ]
    }
   ],
   "source": [
    "import statistics #经测试仅适合于低版本python\n",
    "y,x = statistics.cpdf(data,kernel='Epanechnikov')\n",
    "plt.plot(ecdf.x,ecdf.y,label='Ordinary')\n",
    "plt.plot(x,y,label='Kernel')\n",
    "plt.xlabel('data',fontsize=20)\n",
    "plt.ylabel('Empirical CDF',fontsize=15)\n",
    "plt.legend(loc='best')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
